package com.ruoyi.web.controller.startplan.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AwStartPlan;
import com.ruoyi.system.service.IAwStartPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 启动计划Controller
 *
 * @author anxinr
 * @date 2023-08-11
 */
@RestController
@RequestMapping("/awPlan/plan")
public class AwStartPlanController extends BaseController
{
    @Autowired
    private IAwStartPlanService awStartPlanService;

    /**
     * 查询启动计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(AwStartPlan awStartPlan)
    {
        startPage();
        List<AwStartPlan> list = awStartPlanService.selectAwStartPlanList(awStartPlan);
        return getDataTable(list);
    }

    /**
     * 导出启动计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:export')")
    @Log(title = "启动计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AwStartPlan awStartPlan)
    {
        List<AwStartPlan> list = awStartPlanService.selectAwStartPlanList(awStartPlan);
        ExcelUtil<AwStartPlan> util = new ExcelUtil<AwStartPlan>(AwStartPlan.class);
        util.exportExcel(response, list, "启动计划数据");
    }

    /**
     * 获取启动计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(awStartPlanService.selectAwStartPlanById(id));
    }

    /**
     * 新增启动计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:add')")
    @Log(title = "启动计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AwStartPlan awStartPlan)
    {
        return toAjax(awStartPlanService.insertAwStartPlan(awStartPlan));
    }

    /**
     * 修改启动计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:edit')")
    @Log(title = "启动计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AwStartPlan awStartPlan)
    {
        return toAjax(awStartPlanService.updateAwStartPlan(awStartPlan));
    }

    /**
     * 删除启动计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:remove')")
    @Log(title = "启动计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(awStartPlanService.deleteAwStartPlanByIds(ids));
    }

    @GetMapping("/setDefault")
    public AjaxResult setDefault(@RequestParam("id") Long id) {
        awStartPlanService.setDefault(id) ;
        return success() ;
    }
}
